(function ($) {
    var addListener = function () {
        $("#cancel").bind("click", function () {
            window.location.href = "/html/admin/menu";
        });

        $("#submit").bind("click", function () {
            $(this).prop("disabled", "disabled");

            $.ajax("/api/menus", {
                method: "post",
                dataType: "json",
                contentType: "application/json",
                success: function (data) {
                    if (data.code === 200) {
                        parent.layer.msg("成功");
                    } else {
                        parent.layer.msg("失败, 请联系管理员");
                    }

                    setTimeout(function () {
                        window.location.href = "/html/admin/menu";
                    }, 1000);
                },
                data: JSON.stringify({
                    name: $("#name").val(),
                    type: $("#type").val(),
                    url: $("#url").val(),
                    code: $("#code").val(),
                    icon: $("#icon").val(),
                    id: $("#id").val()
                })
            });
        });
    };

    addListener();
})(jQuery);